import SearchTablePage from '@/components/SearchTablePage';
import { PERMISSION_KEY_OPERATE_LOG } from '@/constants';
import { getOperateLogList } from '@/services/system/log';
import { useModel } from '@umijs/max';

const OperateLog: React.FC = () => {
  const { initialState } = useModel('@@initialState');
  return (
    <>
      <SearchTablePage<API.OperateLog>
        tableName="操作日志"
        getRowsByPage={getOperateLogList}
        rowSelection={false}
        permissionKey={PERMISSION_KEY_OPERATE_LOG}
        columns={[
          {
            title: '操作日志 ID',
            dataIndex: 'id',
            hideInTable: true,
            hideInSearch: true,
          },
          {
            title: '请求地址',
            dataIndex: 'requestUrl',
            showDetail: true,
            hideInSearch: true,
          },
          {
            title: '用户 ID',
            dataIndex: 'userId',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '用户名称',
            dataIndex: 'userName',
            hideInSearch: true,
          },
          {
            title: '用户类型',
            dataIndex: 'userType',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '模块名称',
            dataIndex: 'module',
          },
          {
            title: '操作名',
            dataIndex: 'name',
            hideInSearch: true,
          },
          {
            title: '操作类型',
            dataIndex: 'type',
            valueType: 'tag',
            valueEnum: initialState?.system_operate_type?.tagValueEnum,
          },
          {
            title: '操作内容',
            dataIndex: 'content',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '拓展字段',
            dataIndex: 'exts',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '请求方法名',
            dataIndex: 'requestMethod',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '用户 IP',
            dataIndex: 'userIp',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '浏览器 UA',
            dataIndex: 'userAgent',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: 'Java 方法名',
            dataIndex: 'javaMethod',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: 'Java 方法的参数',
            dataIndex: 'javaMethodArgs',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '操作时间',
            dataIndex: 'startTime',
            valueType: 'dateTime',
          },
          {
            title: '执行时长',
            dataIndex: 'duration',
            hideInSearch: true,
            render: (text: string) => {
              return text ? `${text} ms` : '';
            },
          },
          {
            title: '结果码',
            dataIndex: 'resultCode',
            hideInSearch: true,
          },
          {
            title: '结果提示',
            dataIndex: 'resultMsg',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '结果数据',
            dataIndex: 'resultData',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '创建时间',
            dataIndex: 'createTime',
            valueType: 'dateTime',
            hideInSearch: true,
            hideInModal: true,
            hideInTable: true,
          },
        ]}
      />
    </>
  );
};

export default OperateLog;
